package com.xuetang9.t9.xinhuaxia.controller;

import com.github.pagehelper.PageInfo;
import com.xuetang9.t9.xinhuaxia.beans.Orderlist;
import com.xuetang9.t9.xinhuaxia.beans.UserOrderlist;
import com.xuetang9.t9.xinhuaxia.service.IOrderlistService;
import com.xuetang9.t9.xinhuaxia.service.IUserOrderListService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 李亚奇
 * @version 1.0
 * @desc TODO
 * @date 2020/3/4 14:52
 * @copyright liyq
 * @address 成都西部国际金融中心2栋2201
 **/
@RestController
@RequestMapping("userorderlist")
public class UserOrderListController {
    @Autowired
    private IUserOrderListService userOrderListService;

    @PostMapping("save")
    public boolean insert(@RequestBody UserOrderlist userOrderlist){
        boolean insert = userOrderListService.insert(userOrderlist);
        return insert;
    }

    @PostMapping("saveAndSearch")
    public UserOrderlist saveAndSearch(@RequestBody UserOrderlist userOrderlist){
        UserOrderlist newUserOrderList = null;
        System.out.println(userOrderlist);
        Long userid = userOrderlist.getUser().getuUserid();
        userOrderlist.setUoUserid(userid);
        boolean insert = userOrderListService.insert(userOrderlist);
        if (insert){
            newUserOrderList = userOrderListService.queryByProperty(userOrderlist);
            System.out.println(newUserOrderList);
        }
        return newUserOrderList;
    }

    @GetMapping("remove/{id}")
    public boolean remove(@PathVariable(value = "id",required = false) Long id){
        boolean remove = userOrderListService.remove(id);
        return remove;
    }
    @PostMapping("update")
    public boolean update(@RequestBody UserOrderlist userOrderlist){
        boolean update = userOrderListService.update(userOrderlist);
        return update;
    }

    @GetMapping("queryById/{id}")
    public UserOrderlist queryById(@PathVariable(value = "id",required = false) Long id){
        UserOrderlist userOrderlist = userOrderListService.queryById(id);
        return userOrderlist;
    }

    @GetMapping("queryByUserId/{id}")
    public List<UserOrderlist> queryByUserId(@PathVariable(value = "id",required = false) Long id){
        List<UserOrderlist> userOrderlists = userOrderListService.queryByUserId(id);
        return userOrderlists;
    }

    @GetMapping("list/{page}/{perPagesize}")
    public PageInfo<UserOrderlist> queryByPage(@PathVariable(value = "page",required = false) Integer page, @PathVariable(value = "perPagesize",required = false) Integer perPagesize){
        PageInfo<UserOrderlist> pageInfo = userOrderListService.queryByPage(page, perPagesize);
        return pageInfo;
    }


}
